package com.bjpowernode.drp.item.manager;

import com.bjpowernode.drp.item.dao.ItemDao;
import com.bjpowernode.drp.model.Item;
import com.bjpowernode.drp.util.BeansFactory;
import com.bjpowernode.drp.util.PageModel;

public class ItemManagerImp implements ItemManager {

	private ItemDao itemDao;
	
	public ItemManagerImp(){
		itemDao = (ItemDao)BeansFactory.getInstance().getDao(ItemDao.class);
	}
	
	public void addItem(Item item) {
		itemDao.addItem(item);
	}

	public void delItems(String[] itemIds) {
		itemDao.delItems(itemIds);
	}

	public Item getItemById(String itemId) {
		return itemDao.getItemById(itemId);
	}

	public PageModel<Item> getItemPage(int pageNo, int pageSize,
			String itemIdOrName) {
		PageModel<Item> itemPage = new PageModel<Item>();
		itemPage.setPageNo(pageNo);
		itemPage.setPageSize(pageSize);
		itemPage.setList(itemDao.getItemList(pageNo, pageSize, itemIdOrName));
		int items = itemDao.getItemCount();
		itemPage.setTotalPages((items + (pageSize - 1))/pageSize);
		return itemPage;
	}

	public void modify(Item item) {
		itemDao.modifyItem(item);
	}

}
